<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script>
function chk1(data){
	if(!data.categoryName.value.trim()){
		$("#error").html("카테고리명을 입력하세요");

		return false;
	}
}
function chk2(){
	var flag = confirm("영구적으로 삭제됩니다, 삭제하시겠습니까?");
	if(flag){
		return true;
	}else{
		return false;		
	}
}
</script>
<style type="text/css">
 	hr {border:#B061BF 2px solid;}
  	.headline {margin-top: 0px; margin-bottom: 10px; }
  	.headtext {text-align:center; font-weight: bolder; color:black; margin-top: 20px; margin-bottom: 0px; font-style: 돋음; }
</style>
<h2 class="headtext">카테고리등록</h2>

<table align="center">
	<tr>
		<td></td>
		<td>
			<table align="center">
				<tr>
					<td height="20">
						<c:choose>
							<c:when test="${requestScope.error_message != null}">
								<div align="center" style="color: red;">${requestScope.error_message}</div>
							</c:when>
							<c:otherwise>
								<div id="error" align="center" style="color: red;"></div>
							</c:otherwise>
						</c:choose>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
			<form action="/droowa/product/firstCategory.do" onsubmit="return chk1(this)" method="post">
			<table align="center">
				<tr>
					<td align="center" style="background-color:#453949; color: white;"><label>카테고리명</label></td>
					<td colspan="2" align="center">
						<input type="text" name="categoryName" id="categoryName" placeholder="카테고리를 입력하세요"  style="width:157px;">
					</td>
					<td>
						<input type="hidden" name="fix" value="false">
						<input type="submit" value="등록" style="width:40px;">
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<table align="center" border='1'>
				<tr align="center" style="background-color:#453949; color: white;">
					<td width="65"><label>아이디</label></td>
					<td width="237"><label>기본 카테고리</label></td>
				</tr>
				<c:forEach items="${requestScope.fixedList}" var="category">
				<tr align="center">
					<td>${category.categoryId}</td>
					<td>${category.categoryName}</td>
				</tr>
				</c:forEach>
			</table>
		</td>
		<td valign="top">
			<table align="center" border='1'>
				<tr align="center" style="background-color:#453949; color: white;">
					<td width="65"><label>아이디</label></td>
					<td width="155"><label>카테고리</label></td>
					<td width="40"><label>수정</label></td>
					<td width="40"><label>삭제</label></td>
				</tr>
			<c:forEach items="${requestScope.unFixedList}" var="category">
				<tr align="center">
					<td>${category.categoryId}</td>
					<td>${category.categoryName}</td>
					<td>
						<a href="/droowa/product/getCategoryId.do?categoryId=${category.categoryId}">
							<input type="button" value="수정" id="id" name="${category.categoryId}" style="width:40px;">
						</a>
					</td>
					<td>
						<a href="/droowa/product/removeCategory.do?categoryId=${category.categoryId}">
							<input type="button" value="삭제"  onclick="return chk2()" style="width:40px;">
						</a>
					</td>
				</tr>
			</c:forEach>
			</table>	
		</td>
	</tr>
</table>